<template>
  <div>
    <el-form ref="optForm" :model="form" label-width="90px">
    <div class="ledgerTitle">项目信息</div>
      <el-row>
        <el-col :span="6">
          <el-form-item label-width="100px" label="项目编号: " prop="projectCode">
            {{form.projectCode}}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="100px" label="项目名称:" prop="projectName">
            {{form.projectName}}
          </el-form-item>
        </el-col>
      </el-row>
    <div class="ledgerTitle">基本信息</div>
      <el-row>
        <el-col>
          <el-form-item label-width="100px" label="查询问题:" prop="auditMatter">
            <pre class="pre-style">{{ form.auditMatter }}</pre>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label-width="100px" label="要求反馈时间:" prop="auditMatter">
            {{form.feedbackTime}}
          </el-form-item>
        </el-col>
      </el-row>
      <div class="ledgerTitle">被审计单位答复</div>
      <el-row>
        <el-col>
          <el-form-item label-width="100px" label="答复:" prop="auditPurpose">
            <pre class="pre-style">{{ form.providerOpinion }}</pre>
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label-width="100px" label="附件:">
            <el-upload
              class="upload-demo"
              action="/admin/sys-file/upload"
              :file-list="fileList"
              :on-preview="handlePreview"
              :show-file-list="true">
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="ledgerTitle">审计查询单文书</div>
      <el-row >
        <el-col :span="24">
          <el-form-item label-width="100px" label="审计查询单:" prop="projectName">
            <web-document :form-data="form" readWord="view" :pageType="'evidence'" @createWordfile="wordFileHandle" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>

import {getEvidence} from "@/api/adis/execute/evidence";
import WebDocument from '@/components/form/webDocument.vue';

export default {
  name: 'EngineeringEvidenceView',
  props: {
    id: {
      type: String,
      default: ''
    },
    params: {
      type: Object,
    },
    isAudit: {
      type: Boolean,
      default: false,
    }
  },
  components: {
    WebDocument
  },
  dictTypes: ['audit_type'],
  data() {
    return {
      pointForm: {},
      form:{},
      fileList:[],

    }
  },
  watch: {
    id: {
      handler(val) {
        if (val) {
          getEvidence(this.id).then((res) => {
            if (res.data.data !== null){
              this.handleEvidenceResponse(res.data.data)
              this.$emit('data-loaded', true);
            } else {
              this.$emit('data-loaded', false);
            }
          }).catch(() => {
            this.$emit('data-loaded', false);
          });
        }
      },deep: true, immediate: true
    },
    params: {
      handler(val){
        if (val){
          this.handleEvidenceResponse(val)
        }
      },deep: true, immediate: true
    },
  },
  methods: {
    handleEvidenceResponse(val) {
      this.form = val;
      this.fileList = this.form.attachments;
      this.fileList.forEach((item) =>{
        item.name = item.fileName;
      })
    },
    handlePreview(file) {
      const a = document.createElement('a');
      let url = file.url ? file.url : file.response.data.url;
      console.log(url);      // let fileName = '你想要的文件名.docx'; // 这里设置你想要的文件名，包括扩展名
      a.setAttribute('download', file.name);
      a.setAttribute('href', url);
      a.click();
    },
    wordFileHandle(e) {
      this.$set(this.form, "wordFile", e.wordFile);
      this.$set(this.form, "evidenceId", e.id);
    },
  }
}
</script>
